//
//  ZGL24hController.m
//  Faker
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZGL24hVC.h"
#import "ZGL24NewsVC.h"
#import "ZGL24VideoVC.h"
#import "ZGL24ClassifiedVC.h"
@interface ZGL24hVC ()
@property(nonatomic, retain)UIViewController *childVC;
@property(nonatomic, retain)ZGL24NewsVC *news;
@property(nonatomic, retain)ZGL24VideoVC *video;
@property(nonatomic, retain)ZGL24ClassifiedVC *classified;
@end

@implementation ZGL24hVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zaihufanhui"] style:(UIBarButtonItemStyleDone) target:self action:@selector(leftBarButtonItem:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    UIBarButtonItem *item_news = [[UIBarButtonItem alloc] initWithTitle:@"要闻" style:(UIBarButtonItemStyleDone) target:self action:@selector(barButtonItem:)];
    item_news.tag = 3100;

    UIBarButtonItem *item_video = [[UIBarButtonItem alloc] initWithTitle:@"视频" style:(UIBarButtonItemStyleDone) target:self action:@selector(barButtonItem:)];
    item_video.tag = 3101;
    item_video.tintColor = [UIColor lightGrayColor];
    
    UIBarButtonItem *item_classified = [[UIBarButtonItem alloc] initWithTitle:@"推荐" style:(UIBarButtonItemStyleDone) target:self action:@selector(barButtonItem:)];
    item_classified.tag = 3102;
    item_classified.tintColor = [UIColor lightGrayColor];

    item_news.tintColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItems = @[item_classified, item_video, item_news];
    
    _news = [[ZGL24NewsVC alloc]init];
    _news.view.frame = CGRectMake(0, 0, Width, Height);
    _video = [[ZGL24VideoVC alloc]init];
    _video.view.frame = CGRectMake(0, 0, Width, Height);
    _classified = [[ZGL24ClassifiedVC alloc]init];
    _classified.view.frame = CGRectMake(0, 0, Width, Height);
    
    _childVC = _news;
    [self.view addSubview:_news.view];
    [self addChildViewController:_news];
}

- (void)leftBarButtonItem:(UIBarButtonItem *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.view.backgroundColor = backColor;
}

- (void)barButtonItem:(UIBarButtonItem *)button{
    if (button.tintColor == [UIColor lightGrayColor]) {
        for (UIBarButtonItem *item in self.navigationItem.rightBarButtonItems) {
            item.tintColor = [UIColor lightGrayColor];
        }
        button.tintColor = [UIColor whiteColor];        
        if (button.tag == 3100) {
            [self addChildViewController:_news];
            [self transitionFromViewController:_childVC toViewController:_news duration:0 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:^(BOOL finish){
                [_childVC removeFromParentViewController];
                _childVC = _news;
            }];
        }else if (button.tag == 3101) {
            [self addChildViewController:_video];
            [self transitionFromViewController:_childVC toViewController:_video duration:0 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:^(BOOL finish){
                [_childVC removeFromParentViewController];
                _childVC = _video;
            }];
        }else{
            [self addChildViewController:_classified];
            [self transitionFromViewController:_childVC toViewController:_classified duration:0 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:^(BOOL finish){
                [_childVC removeFromParentViewController];
                _childVC = _classified;
            }];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
